package br.edu.ufabc.gtrnp.helppo.util;

import static br.edu.ufabc.gtrnp.helppo.util.RPCOpenSimParameters.SERVER_URL_RPC;

import java.io.IOException;
import java.net.URL;
import java.util.ResourceBundle;

import org.apache.xmlrpc.client.XmlRpcClient;
import org.apache.xmlrpc.client.XmlRpcClientConfigImpl;

public class RpcClientSingleton {

	private static XmlRpcClient xmlRpcClient;

	public static XmlRpcClient getInstance() throws IOException {
		if (xmlRpcClient == null) {
			xmlRpcClient = new XmlRpcClient();
			configure(xmlRpcClient);
		}

		return xmlRpcClient;
	}

	private static void configure(XmlRpcClient client_) throws IOException {

		ResourceBundle properties = HelppoProperties.getInstance();
		XmlRpcClientConfigImpl configImpl = new XmlRpcClientConfigImpl();
		configImpl.setServerURL(new URL(properties.getString(SERVER_URL_RPC)));
		client_.setConfig(configImpl);

	}
}
